<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工资单号" prop="salaryBillNumber">
        <el-input
          v-model="queryParams.salaryBillNumber"
          placeholder="请输入工资单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工资月份" prop="salaryBillMonth">
        <el-date-picker clearable
          v-model="queryParams.salaryBillMonth"
          style="width: 205px"
          type="month"
          value-format="yyyy-MM"
          placeholder="请选择工资月份">
        </el-date-picker>
      </el-form-item>
      <!--el-form-item label="公司" prop="company">
        <el-input
          v-model="queryParams.company"
          placeholder="请输入公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item-->
      <el-form-item label="司机姓名" prop="driverName">
        <el-input
          v-model="queryParams.driverName"
          placeholder="请输入司机姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--el-form-item label="车牌号码" prop="vehicleLicenseNumber">
        <el-input
          v-model="queryParams.vehicleLicenseNumber"
          placeholder="请输入车牌号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆标记" prop="vehicleMark">
        <el-input
          v-model="queryParams.vehicleMark"
          placeholder="请输入车辆标记"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="趟数" prop="tripNumber">
        <el-input
          v-model="queryParams.tripNumber"
          placeholder="请输入趟数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="重量(吨)" prop="freightWeight">
        <el-input
          v-model="queryParams.freightWeight"
          placeholder="请输入重量(吨)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="件数" prop="freightNumber">
        <el-input
          v-model="queryParams.freightNumber"
          placeholder="请输入件数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运输地点" prop="transportLocation">
        <el-input
          v-model="queryParams.transportLocation"
          placeholder="请输入运输地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基本工资" prop="basicSalary">
        <el-input
          v-model="queryParams.basicSalary"
          placeholder="请输入基本工资"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="未结工资" prop="unsettledSalary">
        <el-input
          v-model="queryParams.unsettledSalary"
          placeholder="请输入未结工资"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="扣款" prop="deductSalary">
        <el-input
          v-model="queryParams.deductSalary"
          placeholder="请输入扣款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实发工资" prop="netSalary">
        <el-input
          v-model="queryParams.netSalary"
          placeholder="请输入实发工资"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="司机签字" prop="signature">
        <el-input
          v-model="queryParams.signature"
          placeholder="请输入司机签字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input
          v-model="queryParams.remark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="园区代码" prop="parkCode">
        <el-input
          v-model="queryParams.parkCode"
          placeholder="请输入园区代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 205px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item-->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['statistic:monthsalary:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['statistic:monthsalary:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['statistic:monthsalary:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['statistic:monthsalary:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" @computeTable="computeTableHeight"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="monthsalaryList" @selection-change="handleSelectionChange" border :height="tableHeight" :row-style="{height:'35px'}" :cell-style="{padding:'0px'}">
      <el-table-column type="selection" width="45" align="center" />
      <el-table-column type="index" prop="" width="55" label="序号" align="center" >
        <template slot-scope="scope">
          <span>{{ scope.$index+1 +(queryParams.pageNum-1)*queryParams.pageSize }}</span>
        </template>
      </el-table-column>
      <!--el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100%">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['statistic:monthsalary:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['statistic:monthsalary:remove']"
          >删除</el-button>
        </template>
      </el-table-column-->
      <!--el-table-column label="账单ID" align="center" prop="salaryBillId" /-->
      <el-table-column label="工资单号" align="center" prop="salaryBillNumber" width="160" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <router-link :to="'/statistic/monthsalary-relatewaybill/index/' + scope.row.salaryBillId" class="link-type">
            <span>{{ scope.row.salaryBillNumber }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="工资月份" align="center" prop="salaryBillMonth" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.salaryBillMonth, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <!--el-table-column label="公司" align="center" prop="company" /-->
      <el-table-column label="司机姓名" align="center" prop="driverName" />
      <el-table-column label="车牌号码" align="center" prop="vehicleLicenseNumber" width="110" :show-overflow-tooltip="true" />
      <!--el-table-column label="车辆标记" align="center" prop="vehicleMark" /-->
      <el-table-column label="趟数" align="center" prop="tripNumber" />
      <el-table-column label="重量(吨)" align="center" prop="freightWeight" />
      <!--el-table-column label="件数" align="center" prop="freightNumber" />
      <el-table-column label="运输地点" align="center" prop="transportLocation" />
      <el-table-column label="基本工资" align="center" prop="basicSalary" /-->
      <el-table-column label="未结工资" align="center" prop="unsettledSalary" />
      <el-table-column label="扣款" align="center" prop="deductSalary" />
      <el-table-column label="实发工资" align="center" prop="netSalary" />
      <!--el-table-column label="司机签字" align="center" prop="signature" /-->
      <el-table-column label="备注" align="center" prop="remark" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改月工资表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="工资单号" prop="salaryBillNumber">
          <el-input v-model="form.salaryBillNumber" placeholder="请输入工资单号" clearable />
        </el-form-item>
        <el-form-item label="工资月份" prop="salaryBillMonth">
          <el-date-picker clearable
            v-model="form.salaryBillMonth"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择工资月份"
            style="width: 340px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="公司" prop="company">
          <el-input v-model="form.company" placeholder="请输入公司" clearable />
        </el-form-item>
        <el-form-item label="司机姓名" prop="driverName">
          <el-input v-model="form.driverName" placeholder="请输入司机姓名" clearable />
        </el-form-item>
        <el-form-item label="车牌号码" prop="vehicleLicenseNumber">
          <el-input v-model="form.vehicleLicenseNumber" placeholder="请输入车牌号码" clearable />
        </el-form-item>
        <el-form-item label="车辆标记" prop="vehicleMark">
          <el-input v-model="form.vehicleMark" placeholder="请输入车辆标记" clearable />
        </el-form-item>
        <el-form-item label="趟数" prop="tripNumber">
          <el-input v-model="form.tripNumber" placeholder="请输入趟数" clearable />
        </el-form-item>
        <el-form-item label="重量(吨)" prop="freightWeight">
          <el-input v-model="form.freightWeight" placeholder="请输入重量(吨)" clearable />
        </el-form-item>
        <el-form-item label="件数" prop="freightNumber">
          <el-input v-model="form.freightNumber" placeholder="请输入件数" clearable />
        </el-form-item>
        <el-form-item label="运输地点" prop="transportLocation">
          <el-input v-model="form.transportLocation" placeholder="请输入运输地点" clearable />
        </el-form-item>
        <el-form-item label="基本工资" prop="basicSalary">
          <el-input v-model="form.basicSalary" placeholder="请输入基本工资" clearable />
        </el-form-item>
        <el-form-item label="未结工资" prop="unsettledSalary">
          <el-input v-model="form.unsettledSalary" placeholder="请输入未结工资" clearable />
        </el-form-item>
        <el-form-item label="扣款" prop="deductSalary">
          <el-input v-model="form.deductSalary" placeholder="请输入扣款" clearable />
        </el-form-item>
        <el-form-item label="实发工资" prop="netSalary">
          <el-input v-model="form.netSalary" placeholder="请输入实发工资" clearable />
        </el-form-item>
        <el-form-item label="司机签字" prop="signature">
          <el-input v-model="form.signature" placeholder="请输入司机签字" clearable />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" clearable />
        </el-form-item>
        <el-form-item label="园区代码" prop="parkCode">
          <el-input v-model="form.parkCode" placeholder="请输入园区代码" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMonthsalary, getMonthsalary, delMonthsalary, addMonthsalary, updateMonthsalary } from "@/api/statistic/monthsalary";

export default {
  name: "Monthsalary",
  data() {
    return {
      // 定义列表高度
      tableHeight: 430,
      // 定义查询高度
      queryHeight: 200,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 月工资表表格数据
      monthsalaryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 园区代码时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        salaryBillNumber: null,
        salaryBillMonth: null,
        company: null,
        driverName: null,
        vehicleLicenseNumber: null,
        vehicleMark: null,
        tripNumber: null,
        freightWeight: null,
        freightNumber: null,
        transportLocation: null,
        basicSalary: null,
        unsettledSalary: null,
        deductSalary: null,
        netSalary: null,
        signature: null,
        remark: null,
        parkCode: null,
        createBy: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    this.$nextTick(() =>{
      // 根据浏览器高度设置初始高度 - 按钮行高度28 - 页码行高度28 - （面包屑+TAB行）高度160
      this.queryHeight = this.$refs.queryForm.$el.offsetHeight;
      this.tableHeight = window.innerHeight - this.$refs.queryForm.$el.offsetHeight - 28 - 28 - 160;
      // 监听浏览器高度变化，改变表格高度
      window.onresize = () =>{
        this.tableHeight = window.innerHeight - this.$refs.queryForm.$el.offsetHeight - 28 - 28 - 160;
      }
    })
  },
  methods: {
    /** 查询月工资表列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listMonthsalary(this.queryParams).then(response => {
        this.monthsalaryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        salaryBillId: null,
        salaryBillNumber: null,
        salaryBillMonth: null,
        company: null,
        driverName: null,
        vehicleLicenseNumber: null,
        vehicleMark: null,
        tripNumber: null,
        freightWeight: null,
        freightNumber: null,
        transportLocation: null,
        basicSalary: null,
        unsettledSalary: null,
        deductSalary: null,
        netSalary: null,
        signature: null,
        remark: null,
        dataRealm: null,
        parkCode: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.salaryBillId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加月工资表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const salaryBillId = row.salaryBillId || this.ids
      getMonthsalary(salaryBillId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改月工资表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.salaryBillId != null) {
            updateMonthsalary(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMonthsalary(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const salaryBillIds = row.salaryBillId || this.ids;
      this.$modal.confirm('是否确认删除月工资表编号为"' + salaryBillIds + '"的数据项？').then(function() {
        return delMonthsalary(salaryBillIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('statistic/monthsalary/export', {
        ...this.queryParams
      }, `月工资表_${this.parseTime(new Date(), '{y}{m}{d}_{h}{i}')}.xlsx`)
    },
    computeTableHeight(){
      if( this.showSearch==true ){
        this.tableHeight = window.innerHeight - this.queryHeight - 28 - 28 - 160;
      } else {
        this.tableHeight = window.innerHeight - 28 - 28 - 160;
      }
    }
  }
};
</script>
